<template>
  <div class="content">
    <div class="top-block">
      <div class="title-item">
        <div class="title">全部行业</div>
        <div class="title">{{count}}/{{max}}</div>
      </div>
      <div class="total-block" v-if="selectList.length>0">
        <div class="total">已选</div>
        <div class="total-show">
          <div class="box">
            <div class="total-item" :key="item.id" v-for="(item,index) in selectList">{{item.jobTitle}}
              <i class="el-icon-close" @click="deleteItem(index)"></i>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="category">
      <div class="second-category-block ">
        <div class="first-category-block ">
          <div :key="item.id" v-for="(item,index) in category" :class="menuActive==item.id?'active':''"
                class="item-list-block">
            <div class="title1">{{item.jobTitle}}</div>
            <div class="item-list-block" :key="item1.id" v-for="(item1,index) in item.subLevelModelList">
              <div class="title">{{item1.jobTitle}}</div>
              <div class="item-block">
                <div :key="item2.id" v-for="(item2,index2) in item1.subLevelModelList"
                      :class="selectList.includes(item2)?'active':''" @click="changeMenuSelected(item2)"
                      class="menu-item">{{item2.jobTitle}}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {findJobNameApi} from "@/api/quick";
import {
  multipleChoiceChange
} from "@/utils/utils"
export default {
  name: "Industry",
  emits:['dialogVisible'],
  data(){
    return{
      jobLoading:false,
      category: [],
      currentChild: null,
      menuActive: null,
      selectedObj: {},
      selectIds: [],
      selectList: [],
      max:3,
      count:0,
      jobTitleList: []
    }
  },
  methods:{
    deleteItem(index) {
      var that = this;
      that.selectList.splice(index, 1)
      this.count=this.selectList.length
    },
    getFindJob(){
      this.jobLoading=true
      findJobNameApi().then((res)=>{
        this.category = res;
        this.menuActive = this.category[0].id
        this.currentChild = this.category[0].subLevelModelList
      }).finally(()=>{
        this.jobLoading=false
      })
    },
    changeMenuSelected(item) {
      multipleChoiceChange(this.selectList, item, 3)
      this.count=this.selectList.length
    },
    handleClose() {
      this.$emit("child",);
    },
    submit() {
      let copy = JSON.parse(JSON.stringify(this.selectList));
      if (copy.length === 0) {
        this.$message.error('请至少选择一个！');
      }
      else {
        this.$emit("child",copy);
      }
      this.jobTitleList = copy[0].jobTitle
      this.$emit('listenToChildEvent',this.jobTitleList)
    },
  },
  mounted() {
    this.getFindJob()
  }
}
</script>

<style scoped lang="scss">
.content{
  padding: 30px;
  max-height: 500px;
  overflow-y: scroll;
  .top-block {
    width: 100%;
    background-color: #fff;
    text-align: center;

    .title-item {
      display: flex;
      flex-direction: row;
      justify-content: space-between;

      .title {
        font-size: 18px;
        font-weight: bold;
      }
    }

    .total-block {
      display: flex;
      align-items: center;
      flex-direction: row;
      margin-top: 20px;

      .total {
        width:40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        color: #000;
      }

      .total-show {
        width: calc(100% - 80px);
        height: 100%;
        padding: 0 10px;
        display: flex;
        align-items: center;

        .box {
          display: flex;
          flex-direction: row;
          align-items: center;
        }

        .total-item {
          //border: 1px solid #027BFE;
          color: #027BFE;
          background: #C7DDFC;
          font-size: 15px;
          margin-right: 10px;
          padding: 3px 10px;
          border-radius: 5px;
          white-space: nowrap;
          display: flex;
          flex-direction: row;

          .el-icon-close {
            font-size: 10px;
            margin-left: 8px;
            color: #027BFE;
          }
        }
      }
    }
  }
  .category {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: center;
    margin-bottom: 50px;

    .second-category-block {
      width: 100%;

      .item-list-block {
        width: 100%;
        display: flex;
        flex-direction: column;
        margin-bottom: 10px;

        .title {
          font-weight: bold;
          padding: 0 10px;
          margin-bottom: 10px;
          font-size: 16px;
        }

        .title1 {
          font-size: 15px;
          font-weight: bold;
          margin-bottom: 15px;
          margin-top: 300px;
          color: #027BFE;
        }

        .item-block {
          width: 100%;
          display: flex;
          flex-direction: row;
          flex-wrap: wrap;
          //padding: 0 10rpx;

          .menu-item {
            padding: 6px 15px;
            width: calc((100% - 30px) / 3);
            color: #313131;
            font-size: 13px;
            margin:5rpx;
            background: #efefef;
            border-radius: 5px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            text-align: center;
            display: flex;
            justify-content: center;
            //border: 1px solid #F6F6F6;
          }

          .menu-item:nth-child(3n) {
            margin-right: 0;
          }



          .menu-item.active {
            color: #027BFE;
            border: 1px solid #027BFE;
            background-color: #fff;
          }
        }

      }
    }
  }
  .category {
     width: 100%;
     display: flex;
     flex-direction: row;
     justify-content: center;
     margin-bottom: 50px;

     .second-category-block {
       width: 100%;

       .item-list-block {
         width: 100%;
         display: flex;
         flex-direction: column;
         margin-bottom: 10px;

         .title {
           font-weight: bold;
           padding: 0 10px;
           margin-bottom: 10px;
           font-size: 16px;
         }

         .title1 {
           font-size: 18px;
           font-weight: bold;
           margin-bottom: 15px;
           margin-top: 30px;
           color: #027BFE;
         }

         .item-block {
           width: 100%;
           display: flex;
           flex-direction: row;
           flex-wrap: wrap;
           //padding: 0 10rpx;

           .menu-item {
             padding: 6px 15px;
             width: calc((100% - 30px) / 3);
             color: #313131;
             font-size: 16px;
             margin: 5px;
             background: #efefef;
             border-radius:5px;
             overflow: hidden;
             white-space: nowrap;
             text-overflow: ellipsis;
             text-align: center;
             display: flex;
             justify-content: center;
             //border: 1px solid #F6F6F6;
           }

           .menu-item:nth-child(3n) {
             margin-right: 0;
           }



           .menu-item.active {
             color: #027BFE;
             border: none;
             background: #C7DDFC;
           }
         }

       }
     }
   }
}
</style>
